package com.company.cloud.pay.modules.bus.producer;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.company.cloud.pay.modules.cache.utils.PayConvertUtils;
import com.company.cloud.pay.modules.third.models.ThirdPayNotifyResp;
import com.company.cloud.pay.modules.third.models.ThirdQueryOrderResp;
import com.company.common.server.config.cloud.ProjectConfig;
import com.company.common.server.config.mq.constant.MQTopicKeys;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * 支付通知
 */
@Service
public class PayProducer {


    @Autowired
    private ProjectConfig projectConfig;


    /**
     * 支付调用日志
     * */


    /**
     * 三方支付查询日志
     * */


    /**
     * 三方支付通知日志
     * */


    /**
     *
     * */


    /**
     * 支付通知各业务系统
     */
    public void payNotify(String serviceCode, ThirdPayNotifyResp resp) {
//		RedisMQMessage message = new RedisMQMessage(this.getPayNotifyTopic(serviceCode));
//		message.setData(this.getPayNotifyData(resp));
//		RedisMQProducer.getInstall().produce(message);
    }


    /**
     * 支付通知:消息内容
     */
    private Map<String, String> getPayNotifyData(ThirdPayNotifyResp resp) {
        Map<String, Object> data = BeanUtil.beanToMap(resp, false, true);
        return PayConvertUtils.mapConvert(data);
    }

    /**
     * 支付通知:topic
     */
    private String getPayNotifyTopic(String serviceCode) {
        return StrUtil.format(MQTopicKeys.MQ_Pay_Notity_Topic, serviceCode);
    }

    /**
     * 支付查询结果回调（Pay消费）
     */
    public void payOrderQuery(String serviceCode, String companyNo, ThirdQueryOrderResp respModel) {
//		RedisMQMessage message = new RedisMQMessage(MQTopicKeys.MQ_PayQuery_Topic);
//		message.setData(this.getPayOrderQueryData(serviceCode,companyNo,respModel));
//		RedisMQProducer.getInstall().produce(message);
    }

    /**
     * 支付查询结果回调:消息内容
     */
    private Map<String, String> getPayOrderQueryData(String serviceCode, String companyNo, ThirdQueryOrderResp resp) {
        Map<String, String> data = new HashMap<String, String>();
        data.put(serviceCode, serviceCode);
        data.put(companyNo, companyNo);
        data.put("data", JSON.toJSONString(resp));
        return data;
    }


}
